<?php
namespace addon\wechat_config\logic;
// +----------------------------------------------------------------------
// | Author: xiaojun <920668625@qq.com>
// +----------------------------------------------------------------------
use app\common\logic\LogicBase;

class WechatRobot extends LogicBase
{
	
	static public function talk($keywords)
	{
		return strip_tags(WechatFunc::http_request('http://api.douqq.com/?key=WFBnOGMwQXM9ZmNVLz1Xa3pwYjRSalljYnhjQUFBPT0&msg='.trim($keywords)));
	}

	/**
	 * 茉莉机器人
	 * http://www.itpk.cn/robot.php
	 * @param  string $keywords 问题文本
	 * @return string           回复内容
	 */
	static public function itpk($keywords){
		$api_key    = '1bceb492f4abef01f05a108f6bea54c1';
		$api_secret = 'qerxkapjgrsu';
		$url='http://i.itpk.cn/api.php?api_key='.$api_key.'&api_secret='.$api_secret.'&question='.$keywords;
		$result = strip_tags(WechatFunc::http_request($url));
		return $result;
	}

	/**
	 * 图灵机器人
	 * http://www.tuling123.com/member
	 * 密钥开关打开了接口一直返回4001(加密方式错误),关了就可正常调用
	 * @param  string $keywords 问题文本
	 * @return string           回复内容
	 */
	static public function tuling($keywords){
		$apikey    = 'b7d91326708b457580617cffff5c814e';
		$apisecret = '880851ef5e7e19ec';
		$url       = 'http://openapi.tuling123.com/openapi/api/v2';
		$param = [
			'reqType'=>0,
			'perception'=>[
				'inputText'=>[
					'text'=>trim($keywords)
				]
			],
			'userInfo'=>[
				'apiKey'=>$apikey,
				'userId'=>'337470'
			]
		];

		$msg 	= '';
		$param  = json_encode($param,JSON_UNESCAPED_UNICODE);
		$output = json_decode(WechatFunc::http_request($url,$param),true);

		if(isset($output['results'][1]['resultType'])){
			$Type = $output['results'][1]['resultType'];
			$msg  .= strip_tags($output['results'][1]['values'][$Type])."\n";
		}
		$Type = $output['results'][0]['resultType'];
		$msg  .= strip_tags($output['results'][0]['values'][$Type]);
		return $msg;
	}
}